package com.example.fw;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class Contacts {
	

	private Set<ContactObject> storredContacts = null;
	
	public Contacts (Collection<ContactObject> contacts) {
		storredContacts = new HashSet<ContactObject>(contacts);
	}

	public Contacts withAdded(ContactObject contact) {
		Contacts contacts2 = new Contacts(storredContacts);
		contact.setId("$$$");
//		WebElement form = findElements(By.tagName("tbody")).get(0);
//		List<WebElement> checkboxes = form.findElements(By.name("selected[]"));
//		String title = checkbox.getAttribute("title");
//		Pattern p = Pattern.compile(".*\\((.*)\\)");
//		 Matcher m = p.matcher(title);
//		if (m.matches()){
//		title = m.group(1);
//		};
//		contact.setTitle(title);
		contacts2 .storredContacts.add(contact);
		contact.setId(null);
		return contacts2;
	}
	public Contacts withoutRemoved(ContactObject contact) {
		Contacts contacts2 = new Contacts(storredContacts);
		contacts2.storredContacts.remove(contact);
		return contacts2;
	}
	public ContactObject getSomeContact() {
		return storredContacts.iterator().next();
}

@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
			+ ((storredContacts == null) ? 0 : storredContacts.hashCode());
	return result;
}

@Override
public boolean equals(Object obj) {
	if (this == obj) {
		return true;
	}
	if (obj == null) {
		return false;
	}
	if (getClass() != obj.getClass()) {
		return false;
	}
	Contacts other = (Contacts) obj;
	if (storredContacts == null) {
		if (other.storredContacts != null) {
			return false;
		}
	} else if (!storredContacts.equals(other.storredContacts)) {
		return false;
	}
	return true;
}
}